public class ListNode {
    int val;
    ListNode next = null;

    public ListNode(int val) {
        this.val = val;
    }
}
class Solution {
    //删除一些节点，使得任意两个相邻的节点的和都是奇数
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     * 初始链表的长度不超过2*10^5
     *  -10^4 <= 权值 <= 10^4
     *
     * @param head ListNode类
     * @return ListNode类
     */
    public ListNode longestList (ListNode head) {
        ListNode p  = null;
        boolean a = false;
        boolean b = false;
        // write code here
        if (head.next == null){
            return head;
        }//如果两个数相加为奇数
        if ((head.val + head.next.val) % 2 != 0) {
            return longestList(head.next.next);
        }
        if ((head.val + head.next.val) % 2 == 0){
            a = head.val % 2 ==0;
            b = head.next.val % 2 == 0;
            if (a && b){//两个都为偶数
                if (head.next.next.val % 2 != 0) {
                    head.next = head.next.next;
                    longestList(head.next.next);
                }
            }
            if ( !a && !b){//两个都为奇数
                if (head.next.next.val % 2 == 0){
                    head.next = head.next.next;
                    longestList(head.next.next);
                }
            }
        }
        return head;
    }//奇+偶=奇
}